﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Utils;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.OpenPersonality
{
    public partial class HomeProfileLivingProcessAdmin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HomeProfileLivingProcessGrid.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(HomeProfileLivingProcessGrid_ItemCommand);
        }

        void HomeProfileLivingProcessGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "InitInsert")
            {
                Response.Redirect("../Site/HomeProfileLivingProcessEdit.aspx");
            }
        }

        protected void IsDeletedCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isDeletedCheckBox = (OwCheckBox)sender;
            var obj = OwOpenHomeProfileLivingProcessBLL.OwGetEntity(isDeletedCheckBox.Text.Trim().OwToInt64TryParse());
            Response.Write(obj.OpenHomeProfileDetailID);
            obj.IsDeleted = isDeletedCheckBox.Checked.ToString().OwToBoolean();
            if (OwOpenHomeProfileLivingProcessBLL.OwSave(obj) > 0)
            {
                HomeProfileLivingProcessGrid.Rebind();
                Alert();
            }
        }
        protected void Alert()
        {
            //MessageNotification.Text = Resources.OpenWeb.ItemUpdateSuccessfullyLabel;
            //MessageNotification.Title = Resources.OpenWeb.ItemUpdateSuccessfullyLabel;
            //MessageNotification.Show();
            //OwNotification notify = new OwNotification();
            //notify.Text = "Item Update Successfully";
            //notify.Title = "Item Update Successfully";
            //notify.Show();
        }

        protected void IsHomeTownCbx_CheckedChanged(object sender, EventArgs e)
        {
            var IsHomeTowncbb = (OwCheckBox)sender;
            if (IsHomeTowncbb.Checked.ToString().OwToBoolean() == true)
            {
                var ods = OwOpenHomeProfileLivingProcessBLL.OwGetByDynamic(null,null,null,null);
                var en = OwOpenHomeProfileLivingProcessBLL.OwGetEntity(IsHomeTowncbb.Text.Trim().OwToInt64TryParse());
                //Response.Write(en.OpenHomeProfileLivingProcessID.ToString());
                foreach (var entity in ods)
                {
                    
                    if (entity.OpenHomeProfileLivingProcessID != en.OpenHomeProfileLivingProcessID)
                    {
                        //if (entity.IsHomeTown == true)
                        //{
                            //Response.Write(entity.OpenHomeProfileLivingProcessID.ToString());
                            entity.IsHomeTown = false;
                            OwOpenHomeProfileLivingProcessBLL.OwSave(entity);
                        //}
                    }
                    else
                    {
                        entity.IsHomeTown = true;
                        OwOpenHomeProfileLivingProcessBLL.OwSave(entity);
                    }
                }
            }
            else
            {
                var en = OwOpenHomeProfileLivingProcessBLL.OwGetEntity(IsHomeTowncbb.Text.Trim().OwToInt64TryParse());
                en.IsHomeTown = false;
                OwOpenHomeProfileLivingProcessBLL.OwSave(en);
            }
            HomeProfileLivingProcessGrid.Rebind();
        }
    }
}